import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        Solution solution = new Solution();
        System.out.println(solution.convert("PAYPALISHIRING", 4));
    }
}


class Solution {
    public String convert(String s, int numRows) {
        if (numRows == 1){
            return s;
        }

        char chars[] = new char[s.length()];
        int cur = 0;
        for(int i = 0; i < numRows; i++){
            if(i == 0 || i == numRows - 1){
                int step = 2 * numRows - 2;
                for(int j = i; j < s.length(); j += step){
                    chars[cur] = s.charAt(j);
                    cur++;
                }
            }
            else {
                int step1 = 2 * numRows - 2 * i - 2;
                int step2 = 2 * i;
                for(int j = i; j < s.length();){
                    chars[cur] = s.charAt(j);
                    cur++;
                    j += step1;
                    if(j < s.length()){
                        chars[cur] = s.charAt(j);
                        cur++;
                        j += step2;
                    }
                }
            }
        }
        return new String(chars);
    }
}